package com.zy.experience_system.util;

import java.util.*;

public class MyStringUtil {
    public static Map<String,String> parse(String s){
        return getStringStringMap(s);
    }

    /**
     * 传入字符串s
     * 解析字符串
     * 将每一行存入List
     * 把列表中每个元素按空格分割
     * 以键值对存入map
     * 返回
     * @param s
     * @return map
     */
    public static Map<String, String> getStringStringMap(String s) {
        List<String> list= Arrays.asList(s.split("\n"));
        HashMap<String,String> map = new LinkedHashMap<>();
        for (String s1 : list) {
            List<String> list1 = Arrays.asList(s1.split(" "));
            map.put(list1.get(0),list1.get(1).replaceAll("(\\\r\\\n|\\\r|\\\n|\\\n\\\r)", ""));
        }
        return map;
    }

    public static void print(Map<String, String> map){
        for (String username : map.keySet()) {
            System.out.println("key: " + username + " value: " + map.get(username));
        }
    }
}
